#include "GnSystemPCH.h"
#include "GnMemoryManager.h"
#include "GnDebugAllocator.h"
#include "GnStandardAllocator.h"

GnMemoryManager* GnMemoryManager::msMemManager = 0;

//---------------------------------------------------------------------------
bool GnMemoryManager::IsInitialized()
{
	return msMemManager != 0;
}
//---------------------------------------------------------------------------
void GnMemoryManager::_EBMStartup()
{
	msMemManager = GnExternalNew GnMemoryManager();
#ifdef GN_MEMORY_DEBUGGER
	msMemManager->mAllocator = GnExternalNew GnDebugAllocator(GnExternalNew GnStandardAllocator());
#else // #ifdef GN_MEMORY_DEBUGGER
	msMemManager->mAllocator = GnExternalNew GnStandardAllocator();
#endif // #ifdef GN_MEMORY_DEBUGGER
	msMemManager->mAllocator->Initialize();
}
//---------------------------------------------------------------------------
void GnMemoryManager::_EBMShutdown()
{
	GnAssert(msMemManager->mAllocator);
	msMemManager->mAllocator->Shutdown(); 
	GnExternalDelete msMemManager;
	msMemManager = NULL;
}
//---------------------------------------------------------------------------
bool GnMemoryManager::VerifyAddress(const void* pvMemory)
{
	GnAssert(msMemManager->mAllocator);
#ifdef GN_MEMORY_DEBUGGER
	return msMemManager->mAllocator->VerifyAddress(pvMemory);
#else
	return true;
#endif
}
//---------------------------------------------------------------------------
